﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;

namespace SportsStore.UI.HtmlHelpers
{
    public static class PagingHelpers
    {
        public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pageInfo, Func<int, String> pageUrl)
        {
            StringBuilder result = new StringBuilder();;
            for(int i=1;i<=pageInfo.TotalPages;i++)
            {
                TagBuilder liTag = new TagBuilder("li");
                TagBuilder tag = new TagBuilder("a");//构造a标签
                tag.MergeAttribute("href", pageUrl(i));
                tag.InnerHtml = "第"+i.ToString()+"页";
                if (i == pageInfo.CurrentPage)
                {
                    liTag.AddCssClass("active");
                    //tag.AddCssClass("selected");
                }
                liTag.InnerHtml = tag.ToString();
                result.Append(liTag.ToString());
            }
            
            return MvcHtmlString.Create(result.ToString());
        }
    }
}